package com.koron.order.repair.controller;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.util.CheckPermission;
import com.koron.order.repair.bean.dto.RepairDetailDto;
import com.koron.order.repair.bean.query.RepairQuery;
import com.koron.order.repair.bean.vo.RepairDetailVo;
import com.koron.order.repair.service.RepairService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (Repair)表控制层
 *
 * @author zhouj
 * @since 2021-09-13 17:42:15
 */
@Api(tags = "计划检修工单主表")
@RestController
@RequestMapping("/repair/")
public class RepairController {

    @Autowired
    private RepairService repairService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或保存")
    @PostMapping("insertOrUpdate")
    public Response<String> insertOrUpdate(@RequestBody RepairDetailDto dto) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), repairService, "insertOrUpdate", String.class, dto));
    }

    @ApiOperation(value = "根据id删除 ")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), repairService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询详情")
    @CheckPermission
    @GetMapping("queryById")
    public Response<RepairDetailVo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), repairService, "queryById", RepairDetailVo.class, id));
    }

    @ApiOperation(value = "查询分页列表")
    @GetMapping("queryList")
    public Response<PageInfo> queryList(RepairQuery query, PageQuery pageQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), repairService, "queryList", PageInfo.class, query, pageQuery));
    }

    @ApiOperation(value = "提交计划检修工单状态 工单id 提交后状态 ")
    @GetMapping("submitRepair")
    public Response<Integer> submitRepair(@RequestParam("repairId") String repairId,
                                    @RequestParam("status") String status) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), repairService, "submitRepair", Integer.class, repairId, status, null));
    }

}
